<%@page import="cn.sendto.model.ClassEntity"%>
<%@page import="cn.sendto.mapper.ClassMapper"%>
<%@page import="cn.sendto.model.StudentEntity"%>
<%@page import="java.util.List"%>
<%@page import="cn.sendto.mapper.IRowMapper"%>
<%@page import="cn.sendto.mapper.StudentMapper"%>
<%@page import="cn.sendto.dbhelper.DBHelper"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@include file="getSession.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta charset="UTF-8">
		<title>添加学生页面</title>
		<link rel="stylesheet" type="text/css" href="css/global.css"/>
	</head>
	<style type="text/css">
		html{
			background: #dddddd;
		}
		.data{
			width: 60%;
			margin:5% auto;
			text-align: left;
			border: 1px solid darkgray;
		}
		.item,.subm{
			width: 100%;
			margin-top: 20px;
			text-align: center;
			border-bottom: 1px dashed darkgray;
			line-height: 30px;
		}
		.item span{
			font-size: 18px;
			color: dimgrey;
		}
		.item input,select{
			width: 30%;
			height: 30px;
			font-size: 16px;
			color: dimgrey;
			
		}
		.subm input{
			width: 100px; 
			height: 50px; 
			font-size: 18px;
		}
	</style>
	<body>
		<div class="data">
			<form action="update.jsp" method="post">
			<%
				request.setCharacterEncoding("utf-8");
			
				//获取参数
				String id = request.getParameter("id");
				
				//操作数据库
				DBHelper helper = new DBHelper();
				
				String sql = "select * from studentinfo s,classinfo c  where s.classid = c.classid and  studentid=?";
				
				IRowMapper mapper = new StudentMapper();
				
				List<StudentEntity> list =helper.executeQuery(sql, mapper, id);
				
				helper.close();
				
				%>
				<input type="hidden" name="id" value="<%=list.get(0).getStudentId()%>"/>
				<div class="item">
					<span>学生姓名：</span><input type="text" name="studentname" id="studentname" value="<%=list.get(0).getStudentName() %>" />
				</div>
				<div class="item">
					<span>学生性别：</span><select name="gender">
					<%
						if(list.get(0).getGender().equals("男")){
							out.print("<option selected='selected' value='1'>男</option>");
							out.print("<option value='2'>女</option>");
							out.print("<option value='3'>不详</option>");
						}else if(list.get(0).getGender().equals("女")){
							out.print("<option value='1'>男</option>");
							out.print("<option selected='selected' value='2'>女</option>");
							out.print("<option value='3'>不详</option>");
						}else if(list.get(0).getGender().equals("不详")){
							out.print("<option value='1'>男</option>");
							out.print("<option value='2'>女</option>");
							out.print("<option selected='selected' value='3'>不详</option>");
						}
					
					%>
					</select>
				</div>
				<div class="item">
					<span>学生年龄：</span><input type="number" name="age" value="<%=list.get(0).getAge() %>" />
				</div>
				<div class="item">
					<span>学生编号：</span><input type="text" name="studentno" value="<%=list.get(0).getStudentno()%>" />
				</div>
				<div class="item">
					<span>学生地址：</span><input type="text" name="address" value="<%=list.get(0).getAddress()%>" />
				</div>
				
				<div class="item">
					<span>学生电话：</span><input type="tel" name="tel" value="<%=list.get(0).getTel()%>" />
				</div>
				
				<div class="item">
					<span>学生班级：</span>
					<select name="classid">
						<%
						String csql ="select * from classinfo";
						
						ClassMapper classMapper = new ClassMapper();
						
						List<ClassEntity> class_list = helper.executeQuery(csql, classMapper, null);
						
						helper.close();
						for(int i =0;i<class_list.size();i++){
							if(class_list.get(i).getClassId()==list.get(0).getClassId()){
								out.print("<option selected='selected' value='"+class_list.get(i).getClassId()+"'>"
							+class_list.get(i).getClassName()+"</option>");
							}else{
								out.print("<option value='"+class_list.get(i).getClassId()+"'>"+class_list.get(i).getClassName()+"</option>");
							}
						}
						%>
					</select>
				</div>
				
				<div class="subm">
					<input   type="submit" value="添加"/>
				</div>
			</form>
		</div>
	</body>
</html>
